package com.zy.openchat.core.model.photo;

import android.os.Parcel;
import android.os.Parcelable;

import com.zy.openchat.core.model.file.FileInfo;

import org.apache.commons.lang3.StringUtils;

public class ProfilePhoto implements Parcelable {
    public String id;
    public FileInfo small;
    public FileInfo big;

    public long fileBigId() {
        if (big != null)
            return big.id;
        return 0;
    }

    public long fileSmallId() {
        if (small != null)
            return small.id;
        return 0;
    }

    public boolean isSmallPhotoDownloaded() {
        if (small != null && small.local != null) {
            return small.local.is_downloading_completed && !StringUtils.isEmpty(small.local.path);
        }
        return false;
    }

    public boolean isBigPhotoDownloaded() {
        if (big != null && big.local != null) {
            return big.local.is_downloading_completed && !StringUtils.isEmpty(big.local.path);
        }
        return false;
    }

    public String localBigPath() {
        if (big != null && big.local != null) {
            return big.local.path;
        }
        return null;
    }

    public String localSmallPath() {
        if (small != null && small.local != null) {
            return small.local.path;
        }
        return null;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeParcelable(this.small, flags);
        dest.writeParcelable(this.big, flags);
    }

    public ProfilePhoto() {
    }

    protected ProfilePhoto(Parcel in) {
        this.id = in.readString();
        this.small = in.readParcelable(FileInfo.class.getClassLoader());
        this.big = in.readParcelable(FileInfo.class.getClassLoader());
    }

    public static final Creator<ProfilePhoto> CREATOR = new Creator<ProfilePhoto>() {
        @Override
        public ProfilePhoto createFromParcel(Parcel source) {
            return new ProfilePhoto(source);
        }

        @Override
        public ProfilePhoto[] newArray(int size) {
            return new ProfilePhoto[size];
        }
    };
}
